home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / WAREZ 1.1 source Folder / warez ƒ / warez code ƒ / warez.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  4.6 KB  |  206 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        warez.c
  4.  
  5. Purpose:    This module handles WAREZ-specific initialization and
  6.             shutdown, memory setup for converting, and a dispatch
  7.             for file conversion.
  8.  
  9.  
  10. WAREZ -=- nostalgia isn't what it used to be
  11. Copyright ©1994, Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "warez.h"
  31. #include "warez meat.h"
  32. #include "warez files.h"
  33. #include "warez file management.h"
  34. #include "warez error.h"
  35. #include "warez progress.h"
  36. #include "program globals.h"
  37. #include "util.h"
  38. #include "msg environment.h"
  39. #include "msg menus.h"
  40.  
  41. unsigned char    gShowSaveDialog;
  42. unsigned char    gAddSuffix;
  43. unsigned char    gShowProgress;
  44. unsigned char    gUseRTF;
  45.  
  46. void InitProgram(void)
  47. {
  48.     int                i,j,k;
  49.     AppFile            myFile;
  50.     
  51.     CountAppFiles(&i, &j);
  52.     if ((j>0) && (i==0))
  53.     {
  54.         for (k=1; k<=j; k++)
  55.         {
  56.             GetAppFiles(1, &myFile);
  57.             MyMakeFSSpec(myFile.vRefNum, 0, myFile.fName, &inputFS);
  58.             StartConvert();
  59.             ClrAppFiles(k);
  60.         }
  61.     }
  62. }
  63.  
  64. void NewConvert(void)
  65. {
  66.     inputFS.name[0]=outputFS.name[0]=tempFS.name[0]=0x00;
  67.     if (GetSourceFile(&inputFS, FALSE))
  68.         StartConvert();
  69. }
  70.  
  71. void StartConvert(void)
  72. {
  73.     int                err;
  74.     Boolean            notDoneYet;
  75.     
  76.     outputFS=inputFS;
  77.     if (gAddSuffix)
  78.     {
  79.         if (outputFS.name[0]>28)
  80.             outputFS.name[0]=28;
  81.         outputFS.name[++(outputFS.name[0])]='.';
  82.         outputFS.name[++(outputFS.name[0])]='K';
  83.         outputFS.name[++(outputFS.name[0])]='0';
  84.         outputFS.name[++(outputFS.name[0])]='0';
  85.         outputFS.name[++(outputFS.name[0])]='L';
  86.     }
  87.     deleteTheThing=TRUE;
  88.     
  89.     if (gShowSaveDialog)
  90.         if (!GetDestFile(&outputFS, &deleteTheThing))
  91.             return;
  92.  
  93.     gInputNeedsUpdate=TRUE;
  94.     gOutputNeedsUpdate=FALSE;
  95.     gInputOffset=gOutputOffset=gAbsoluteOffset=0L;
  96.     
  97.     InitFiles();
  98.     HandleError(err=OpenInputFile());
  99.     if (err!=allsWell)
  100.         return;
  101.     HandleError(err=CreateTempFile());
  102.     if (err!=allsWell)
  103.     {
  104.         FinalizeFiles(FALSE);
  105.         return;
  106.     }
  107.     HandleError(err=SetupTempFile());
  108.     if (err!=allsWell)
  109.     {
  110.         FinalizeFiles(FALSE);
  111.         return;
  112.     }
  113.     
  114.     gInputBuffer=NewPtrClear(INPUT_BUFFER_MAX+16);
  115.     if (gInputBuffer==0L)
  116.     {
  117.         FinalizeFiles(FALSE);
  118.         HandleError(kNoMemory);
  119.         return;
  120.     }
  121.     
  122.     gOutputBuffer=NewPtrClear(OUTPUT_BUFFER_MAX+16);
  123.     if (gOutputBuffer==0L)
  124.     {
  125.         FinalizeFiles(FALSE);
  126.         DisposePtr(gInputBuffer);
  127.         HandleError(kNoMemory);
  128.         return;
  129.     }
  130.     
  131.     gInProgress=TRUE;
  132.     AdjustMenus();
  133.     DrawMenuBar();
  134.     
  135.     if (showThatTharProgress)
  136.     {
  137.         OpenProgressDialog(gInputLength, "\pWAREZ");
  138.         SetProgressText("\pK0NVERT1NG ",inputFS.name, "\p...","\p");
  139.     }
  140.     
  141.     gInWord=gSeenBackslash=FALSE;
  142.     gCurlyLevel=0;
  143.     
  144.     notDoneYet=TRUE;
  145.     err=allsWell;
  146.     while ((notDoneYet) && (err==allsWell) && (gAbsoluteOffset<gInputLength))
  147.     {
  148.         if (gInputNeedsUpdate)
  149.         {
  150.             if (gInputOffset>0L)
  151.                 ShiftInputBuffer();
  152.             HandleError(err=ReadInputFile(inputRefNum, gInputBuffer+
  153.                 gWhatsReallyInInputBuffer, INPUT_BUFFER_MAX+16-gWhatsReallyInInputBuffer));
  154.             gInputNeedsUpdate=FALSE;
  155.             if (showThatTharProgress)
  156.             {
  157.                 UpdateProgressDialog(gAbsoluteOffset);
  158.                 notDoneYet=DealWithOtherPeople();
  159.             }
  160.         }
  161.         
  162.         if ((notDoneYet) && (err==allsWell) && (gOutputNeedsUpdate))
  163.         {
  164.             HandleError(err=WriteTempFile(outputRefNum, gOutputBuffer, gOutputOffset));
  165.             gOutputOffset=0L;
  166.             gOutputNeedsUpdate=FALSE;
  167.         }
  168.         
  169.         if ((notDoneYet) && (err==allsWell))
  170.             ConvertIt();
  171.     }
  172.     
  173.     if (showThatTharProgress)
  174.     {
  175.         UpdateProgressDialog(gAbsoluteOffset);
  176.         DealWithOtherPeople();
  177.     }
  178.     
  179.     if (gOutputOffset>0L)
  180.     {
  181.         HandleError(err=WriteTempFile(outputRefNum, gOutputBuffer, gOutputOffset));
  182.     }
  183.     
  184.     DisposePtr(gInputBuffer);
  185.     DisposePtr(gOutputBuffer);
  186.     
  187.     FinalizeFiles((notDoneYet) && (err==allsWell));
  188.     
  189.     if (showThatTharProgress)
  190.         DismissProgressDialog();
  191.     gInProgress=FALSE;
  192.     AdjustMenus();
  193.     DrawMenuBar();
  194. }
  195.  
  196. void ShiftInputBuffer(void)
  197. {
  198.     Mymemcpy(gInputBuffer, gInputBuffer+gInputOffset, INPUT_BUFFER_MAX+16-gInputOffset);
  199.     gWhatsReallyInInputBuffer=INPUT_BUFFER_MAX+16-gInputOffset;
  200.     gInputOffset=0L;
  201. }
  202.  
  203. void ShutDownProgram(void)
  204. {
  205. }
  206.